import { IPSModelSortable } from '../../ipsmodel-sortable';
import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEMap } from './ipsdemap';
import { IPSDEMapAction } from './ipsdemap-action';
import { IPSDEMapDataQuery } from './ipsdemap-data-query';
import { IPSDEMapDataSet } from './ipsdemap-data-set';
import { IPSDEMapField } from './ipsdemap-field';
import { IPSSysSFPlugin } from '../../res/ipssys-sfplugin';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEMapImpl extends PSModelObjectImpl implements IPSDEMap, IPSModelSortable {
  get codeName(): string {
    return this.M.codeName;
  }

  protected dstpsde: IPSDataEntity | null = null;

  getDstPSDE(): IPSDataEntity | null {
    if (this.dstpsde != null) return this.dstpsde;
    const value = this.M.getDstPSDE;
    if (value == null) {
      return null;
    }
    this.dstpsde = this.getPSModel4('dataentity.IPSDataEntity', value, 'getDstPSDE') as IPSDataEntity;
    return this.dstpsde;
  }

  get dstPSDE(): IPSDataEntity | null {
    return this.getDstPSDE();
  }

  getDstPSDEMust(): IPSDataEntity {
    const value = this.getDstPSDE();
    if (value == null) {
      throw new Error('未指定映射目标实体对象');
    }
    return value;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get extendMode(): 0 | 2 {
    return this.M.extendMode != null ? this.M.extendMode : 0;
  }

  get mapParams(): IModel {
    return this.M.mapParams;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  protected psdemapactions: IPSDEMapAction[] | null = null;

  getPSDEMapActions(): IPSDEMapAction[] | null {
    if (this.psdemapactions == null) {
      this.psdemapactions = this.fillChildListModel(this.M.getPSDEMapActions, 'dataentity.datamap.IPSDEMapAction') as IPSDEMapAction[];
    }
    return this.psdemapactions;
  }

  get psDEMapActions(): IPSDEMapAction[] | null {
    return this.getPSDEMapActions();
  }

  findPSDEMapAction(objKey: any): IPSDEMapAction | null {
    return this.getPSModel5('dataentity.datamap.IPSDEMapAction', this.getPSDEMapActions(), objKey) as IPSDEMapAction;
  }

  protected psdemapdataqueries: IPSDEMapDataQuery[] | null = null;

  getPSDEMapDataQueries(): IPSDEMapDataQuery[] | null {
    if (this.psdemapdataqueries == null) {
      this.psdemapdataqueries = this.fillChildListModel(this.M.getPSDEMapDataQueries, 'dataentity.datamap.IPSDEMapDataQuery') as IPSDEMapDataQuery[];
    }
    return this.psdemapdataqueries;
  }

  get psDEMapDataQueries(): IPSDEMapDataQuery[] | null {
    return this.getPSDEMapDataQueries();
  }

  findPSDEMapDataQuery(objKey: any): IPSDEMapDataQuery | null {
    return this.getPSModel5('dataentity.datamap.IPSDEMapDataQuery', this.getPSDEMapDataQueries(), objKey) as IPSDEMapDataQuery;
  }

  protected psdemapdatasets: IPSDEMapDataSet[] | null = null;

  getPSDEMapDataSets(): IPSDEMapDataSet[] | null {
    if (this.psdemapdatasets == null) {
      this.psdemapdatasets = this.fillChildListModel(this.M.getPSDEMapDataSets, 'dataentity.datamap.IPSDEMapDataSet') as IPSDEMapDataSet[];
    }
    return this.psdemapdatasets;
  }

  get psDEMapDataSets(): IPSDEMapDataSet[] | null {
    return this.getPSDEMapDataSets();
  }

  findPSDEMapDataSet(objKey: any): IPSDEMapDataSet | null {
    return this.getPSModel5('dataentity.datamap.IPSDEMapDataSet', this.getPSDEMapDataSets(), objKey) as IPSDEMapDataSet;
  }

  protected psdemapfields: IPSDEMapField[] | null = null;

  getPSDEMapFields(): IPSDEMapField[] | null {
    if (this.psdemapfields == null) {
      this.psdemapfields = this.fillChildListModel(this.M.getPSDEMapFields, 'dataentity.datamap.IPSDEMapField') as IPSDEMapField[];
    }
    return this.psdemapfields;
  }

  get psDEMapFields(): IPSDEMapField[] | null {
    return this.getPSDEMapFields();
  }

  findPSDEMapField(objKey: any): IPSDEMapField | null {
    return this.getPSModel5('dataentity.datamap.IPSDEMapField', this.getPSDEMapFields(), objKey) as IPSDEMapField;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDEMapImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'dataentity.datamap.IPSDEMap') return true;
    return super.instanceof(cls);
  }
}
